/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.util.List;

/**
 *
 * @author thaidacvinh
 */
public class LeagueService {
    LeagueDAO leagueDAO;
    private List leagues;
    public LeagueService () {
        leagueDAO = new LeagueDAO();
        leagues = leagueDAO.getAllLeagues();
    }

    /**
     * @return the leagues
     */
    public List getLeagues() {
        return leagues;
    }
    
    public League addLeague(int year, String season, String title) {
        try {
            int id = leagueDAO.insert(year, season, title);
            if (id != -1) {
                League league = new League(id, year, season, title);
                this.leagues.add(league);
                return league;
            }
        } catch (Exception e) {
            System.err.println(e);
        }
        return null;
    }
}
